package com.hzjh.base.ext.widget.recycleview

import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.hzjh.base.ext.databinding.JhPlatformListBinding
import com.hzjh.base.frame.adapter.MutableAdapter
import com.hzjh.base.frame.adapter.SimpleGapItemDecor
import com.hzjh.base.utils.function.dp2px

class JHPlatformList @JvmOverloads constructor(
    context: Context,
    attrs: AttributeSet? = null,
    styleTheme: Int = 0
) : RecyclerView(context, attrs, styleTheme) {
    private val dataList: MutableList<String> = mutableListOf()
    private val dataAdapter by lazy {
        MutableAdapter(dataList).apply {
            addVhDelegate {
                JHPlatformItemVH(JhPlatformListBinding.inflate(LayoutInflater.from(context),it,false))
            }
        }
    }
    init {
        layoutManager = LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false)
        addItemDecoration(
            SimpleGapItemDecor(horGap = 14.dp2px())
        )
        adapter=dataAdapter
    }

    fun setData(data: List<String>) {
        dataList.clear()
        dataList.addAll(data)
        dataAdapter.notifyDataSetChanged()
    }
}